home *** CD-ROM | disk | FTP | other *** search
/ Learn to Speak Spanish 7 / LSSP_7.ISO / pc / lssp / shared.dir / 00765_Extras Scripts.ls < prev    next >
Encoding:
Text File  |  1998-11-16  |  7.3 KB  |  281 lines

  1. on posePuzzleResponse isCorrect
  2.   global TheMediaQueue, theSound
  3.   if isCorrect then
  4.     set response to "Right"
  5.     set soundNo to random(20)
  6.   else
  7.     set response to "Wrong"
  8.     set soundNo to random(14)
  9.     TheMediaQueue(mFlush)
  10.   end if
  11.   if soundNo <= 9 then
  12.     put "0" after response
  13.   end if
  14.   put soundNo after response
  15.   set theSound to DisposeMedia(theSound)
  16.   set theSound to NewPlaySound(BuildSoundName(response, 1))
  17.   TheMediaQueue(mPlay, theSound, 0, 0, 0, 0)
  18. end
  19.  
  20. on MPCcharToNum charIn
  21.   global charLookup
  22.   set numLines to the number of lines in charLookup
  23.   set theChar to charToNum(charIn)
  24.   set charOut to theChar
  25.   if (charOut < 127) or (the machineType <> 256) then
  26.     return charOut
  27.   end if
  28.   repeat with i = 1 to numLines
  29.     if theChar = value(item 1 of line i of charLookup) then
  30.       set charOut to value(item 2 of line i of charLookup)
  31.     end if
  32.   end repeat
  33.   return charOut
  34. end
  35.  
  36. on checkAnswer correctAnswers, userAnswer
  37.   set failPos to 0
  38.   repeat while correctAnswers <> EMPTY
  39.     set anAnswer to removeExtraSpaces(line 1 of correctAnswers)
  40.     delete line 1 of correctAnswers
  41.     set pos to checkByChar(anAnswer, userAnswer)
  42.     if pos = 0 then
  43.       return 0
  44.     end if
  45.     set failPos to max(failPos, pos)
  46.   end repeat
  47.   return failPos
  48. end
  49.  
  50. on checkByChar theAnswer, userResponse
  51.   set longestLen to max(the number of chars in theAnswer, the number of chars in userResponse)
  52.   repeat with i = 1 to longestLen
  53.     if charToNum(char i of theAnswer) <> charToNum(char i of userResponse) then
  54.       return i
  55.     end if
  56.   end repeat
  57.   return 0
  58. end
  59.  
  60. on longestAnswer answers, separator
  61.   set maxLength to 0
  62.   repeat while answers <> EMPTY
  63.     set pos to offset(separator, answers)
  64.     if pos > 0 then
  65.       set anAnswer to char 1 to pos - 1 of answers
  66.       delete char 1 to pos of answers
  67.     else
  68.       set anAnswer to answers
  69.       set answers to EMPTY
  70.     end if
  71.     if the number of chars in anAnswer > maxLength then
  72.       set maxLength to the number of chars in anAnswer
  73.       set biggestAnswer to anAnswer
  74.     end if
  75.   end repeat
  76.   return biggestAnswer
  77. end
  78.  
  79. on custom_Alert type, StringNum, var
  80.   if type = 1 then
  81.     alert(line StringNum of field "error messages" & var)
  82.     return 
  83.   else
  84.     if type = 2 then
  85.       alert(item 1 of line StringNum of field "error messages" && var && item 2 of line StringNum of field "error messages")
  86.     end if
  87.   end if
  88. end
  89.  
  90. on pointInRect p, r
  91.   if value(item 1 of p) > value(item 1 of r) then
  92.     if value(item 1 of p) < value(item 3 of r) then
  93.       if value(item 2 of p) > value(item 2 of r) then
  94.         return value(item 2 of p) < value(item 4 of r)
  95.       end if
  96.     end if
  97.   end if
  98.   return 0
  99. end
  100.  
  101. on ButtonPressed buttonSprite, pressedName, transitionName
  102.   set isPressed to 1
  103.   set relaxedCast to the castNum of sprite buttonSprite
  104.   if pressedName <> EMPTY then
  105.     set depressedCast to the number of cast pressedName
  106.   else
  107.     set depressedCast to relaxedCast + 1
  108.   end if
  109.   set the castNum of sprite buttonSprite to depressedCast
  110.   updateStage()
  111.   repeat while the mouseDown
  112.     set isPressed to rollOver(buttonSprite)
  113.     if the castNum of sprite buttonSprite = depressedCast <> isPressed then
  114.       if isPressed then
  115.         set the castNum of sprite buttonSprite to depressedCast
  116.       else
  117.         set the castNum of sprite buttonSprite to relaxedCast
  118.       end if
  119.       updateStage()
  120.     end if
  121.   end repeat
  122.   if (transitionName <> EMPTY) and isPressed then
  123.     set the castNum of sprite buttonSprite to the number of cast transitionName
  124.   else
  125.     set the castNum of sprite buttonSprite to relaxedCast
  126.   end if
  127.   updateStage()
  128.   return isPressed
  129. end
  130.  
  131. on removeExtraSpaces theString
  132.   set pos to 1
  133.   repeat while pos <= the number of chars in theString
  134.     set isThisSpace to isSpace(char pos of theString)
  135.     set isNextSpace to isSpace(char pos + 1 of theString)
  136.     if isThisSpace and ((pos = 1) or (pos = the number of chars in theString) or isNextSpace) then
  137.       delete char pos of theString
  138.       next repeat
  139.     end if
  140.     if isThisSpace then
  141.       put " " into char pos of theString
  142.     end if
  143.     set pos to pos + 1
  144.   end repeat
  145.   return theString
  146. end
  147.  
  148. on isSpace c
  149.   return (c = " ") or (c = TAB) or (c = RETURN)
  150. end
  151.  
  152. on caseStringCompare theString1, theString2
  153.   set theResult to 1
  154.   repeat with i = 1 to the number of chars in theString1
  155.     if charToNum(char i of theString1) <> charToNum(char i of theString2) then
  156.       set theResult to 0
  157.     end if
  158.   end repeat
  159.   if the number of chars in theString1 <> the number of chars in theString2 then
  160.     set theResult to 0
  161.   end if
  162.   return theResult
  163. end
  164.  
  165. on globalaccent
  166.   global accentraw, accvowel
  167.   put "s,?,1,n,c" into line 1 of accentraw
  168.   put "223,191,161,241,231,209,199" into line 2 of accentraw
  169.   put "225,233,237,243,250" into line 1 of accvowel
  170.   put "224,232,236,242,249" into line 2 of accvowel
  171.   put "226,234,238,244,251" into line 3 of accvowel
  172.   put "228,235,239,246,252" into line 4 of accvowel
  173.   put "a,e,i,o,u" into line 5 of accvowel
  174. end
  175.  
  176. on checkaccent
  177.   global accent, keycodeObj, keyToPress, accvowel, accentraw
  178.   if the machineType = 256 then
  179.     if accent and (keyToPress = 0) then
  180.       set curkey to the key
  181.       if accent < 5 then
  182.         repeat with i = 1 to 5
  183.           if item i of line 5 of accvowel = curkey then
  184.             dontPassEvent()
  185.             if the shiftDown = 0 then
  186.               set keyToPress to integer(item i of line accent of accvowel)
  187.             else
  188.               set keyToPress to integer(item i of line accent of accvowel) - 32
  189.             end if
  190.             exit repeat
  191.           end if
  192.         end repeat
  193.         set accent to 0
  194.       else
  195.         if the shiftDown then
  196.           repeat with i = 2 to 5
  197.             if item i of line 1 of accentraw = curkey then
  198.               if i < 4 then
  199.                 set keyToPress to integer(item i of line 2 of accentraw)
  200.               else
  201.                 set keyToPress to integer(item i + 2 of line 2 of accentraw)
  202.               end if
  203.               dontPassEvent()
  204.               exit repeat
  205.             end if
  206.           end repeat
  207.         else
  208.           repeat with i = 1 to 5
  209.             if item i of line 1 of accentraw = curkey then
  210.               set keyToPress to integer(item i of line 2 of accentraw)
  211.               dontPassEvent()
  212.               exit repeat
  213.             end if
  214.           end repeat
  215.         end if
  216.         set accent to 0
  217.       end if
  218.     else
  219.       set curkey to the key
  220.       if the commandDown then
  221.         if curkey = "z" then
  222.           set accent to 5
  223.         else
  224.           if curkey = "u" then
  225.             set accent to 4
  226.           else
  227.             if curkey = "\" then
  228.               set accent to 2
  229.             else
  230.               if curkey = "i" then
  231.                 set accent to 3
  232.               else
  233.                 if curkey = "e" then
  234.                   set accent to 1
  235.                 end if
  236.               end if
  237.             end if
  238.           end if
  239.         end if
  240.         if accent then
  241.           set keyToPress to -1
  242.           dontPassEvent()
  243.           return 0
  244.         end if
  245.       end if
  246.     end if
  247.   end if
  248.   return 0
  249. end
  250.  
  251. on min a, b
  252.   if a < b then
  253.     return a
  254.   end if
  255.   return b
  256. end
  257.  
  258. on max a, b
  259.   if a > b then
  260.     return a
  261.   end if
  262.   return b
  263. end
  264.  
  265. on sign num
  266.   if num < 0 then
  267.     return -1
  268.   end if
  269.   return 1
  270. end
  271.  
  272. on clamp value, min, max
  273.   if value > max then
  274.     return max
  275.   end if
  276.   if value < min then
  277.     return min
  278.   end if
  279.   return value
  280. end
  281.